<?php require_once('../Connections/sepolwan_connect.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
include "../txt/url.php";
include "../tambah/date.php";
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_sesi_member = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_sesi_member = $_SESSION['MM_Username'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_sesi_member = sprintf("SELECT * FROM memberdb WHERE email = %s", GetSQLValueString($colname_sesi_member, "text"));
$sesi_member = mysql_query($query_sesi_member, $sepolwan_connect) or die(mysql_error());
$row_sesi_member = mysql_fetch_assoc($sesi_member);
$totalRows_sesi_member = mysql_num_rows($sesi_member);

mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_chat = "SELECT DISTINCT * FROM chat WHERE ke = '".$row_sesi_member['nama_user']."' AND stat = 'ur' ORDER BY id DESC ";
$chat = mysql_query($query_chat, $sepolwan_connect) or die(mysql_error());
$row_chat = mysql_fetch_assoc($chat);
$totalRows_chat = mysql_num_rows($chat);

mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_ikut_me = "SELECT * FROM ikut WHERE dari = '".$row_sesi_member['id']."' ORDER BY id DESC";
$ikut_me = mysql_query($query_ikut_me, $sepolwan_connect) or die(mysql_error());
$row_ikut_me = mysql_fetch_assoc($ikut_me);
$totalRows_ikut_me = mysql_num_rows($ikut_me);
?>
<?php if ($totalRows_sesi_member > 0) { // Show if recordset not empty ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='<?php echo $base ?>images/log.png' rel='shortcut icon'/>
<link href="<?php echo $base ?>gaya/style.css" rel="stylesheet" type="text/css" />
<title>Chat <?php echo $row_sesi_member['full_name']; ?></title>
<script language="javascript" src="<?php echo $base ?>pesan/jquery-1.2.6.min.js"></script>
<script language="javascript" src="<?php echo $base ?>pesan/jquery.timers-1.0.0.js"></script>
<script type="text/javascript">

$(document).ready(function(){
   var j = jQuery.noConflict();
	j(document).ready(function()
	{
		j(".refresh").everyTime(1000,function(i){
			j.ajax({
			  url: "<?php echo $base ?>pesan/reload.php",
			  cache: false,
			  success: function(html){
				j(".refresh").html(html);
			  }
			})
		})
		
	});
	 j('.refresh').css({color:"green"});
});
$(".refresh").scrollTop($(".refresh")[0].scrollHeight);
</script>
</head>

<body>
<div class="refresh">
<?php if ($totalRows_chat > 0) { // Show if recordset not empty ?>
<div style="padding:10px; background:#000; color:#FFF">Pesan Baru</div>
  <?php do { 
if($row_sesi_member['nama_user']==$row_chat['dari'])
$ini=$row_chat['ke'];
if($row_sesi_member['nama_user']==$row_chat['ke'])
$ini=$row_chat['dari'];
$colname_member = "-1";
if (isset($ini)) {
  $colname_member = $ini;
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_member = sprintf("SELECT * FROM memberdb WHERE nama_user = %s", GetSQLValueString($colname_member, "text"));
$member = mysql_query($query_member, $sepolwan_connect) or die(mysql_error());
$row_member = mysql_fetch_assoc($member);
$totalRows_member = mysql_num_rows($member);
?>
  <div id="chat2"><a href="<?php echo $row_member['nama_user']; ?>.html"><div style="border:1px solid #CCC; float:left"><img src="<?php  if(file_exists("../images/member/ava/".md5($row_member['id']).".jpg")) { echo $base."images/member/ava/tester_50_50_".md5($row_member['id']).".jpg"; } else { echo $base."images/member/ava/tester_50_50_default.jpg"; }  ?>" /></div>
    <div style="margin-left:60px; min-height:50px"><strong><?php echo $row_member['full_name']; ?></strong><br />
<font size="-2"><?php echo $row_chat['pesan']; ?></font><br />
<font size="-4" color="#999999"><?php echo tgl_indo($row_chat['waktu']), substr($row_chat['waktu'], 10, 6), " WIB"; ?></font></div></a></div>
  <?php 
  mysql_free_result($member);
  } while ($row_chat = mysql_fetch_assoc($chat)); ?>
  <?php } // Show if recordset not empty ?>
  </div>
<?php if ($totalRows_chat > 0) { // Show if recordset not empty ?>
  
<?php } ?>
<div style="padding:10px; background:#000; color:#FFF">Contact</div>
  <?php do { 
  
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_ikut_ = "SELECT * FROM ikut WHERE dari = '".$row_ikut_me['ke']."' AND ke = '".$row_sesi_member['id']."' AND dari <> ke ORDER BY id DESC";
$ikut_ = mysql_query($query_ikut_, $sepolwan_connect) or die(mysql_error());
$row_ikut_ = mysql_fetch_assoc($ikut_);
$totalRows_ikut_ = mysql_num_rows($ikut_);


  $colname_member = "-1";
if (isset($row_ikut_['dari'])) {
  $colname_member = $row_ikut_['dari'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_member = sprintf("SELECT * FROM memberdb WHERE id = %s", GetSQLValueString($colname_member, "text"));
$member = mysql_query($query_member, $sepolwan_connect) or die(mysql_error());
$row_member = mysql_fetch_assoc($member);
$totalRows_member = mysql_num_rows($member);
if ($totalRows_member>0) {
  ?>
  <div id="chat"><a href="<?php echo $row_member['nama_user']; ?>.html"><div style=" border:1px solid #CCC; float:left"><img src="<?php  if(file_exists("../images/member/ava/".md5($row_member['id']).".jpg")) { echo $base."images/member/ava/tester_50_50_".md5($row_member['id']).".jpg"; } else { echo $base."images/member/ava/tester_50_50_default.jpg"; }  ?>" /></div>
    <div style="margin-left:60px; height:50px;"><strong><?php echo $row_member['full_name']; ?></strong><br />
<font size="-2">( <?php echo $row_member['nama_user']; ?> )</font></div></a></div>
  <?php
}
  mysql_free_result($member);
   } while ($row_ikut_me = mysql_fetch_assoc($ikut_me)); ?>
   <div align="center" style="margin:10px"><font size="-2" color="#999999">Note : hanya untuk orang-orang yang saling mengikuti (follow) dengan anda</font></div>
</body>
</html>
<?php } // Show if recordset not empty 
else { echo "<a href='".$base."'>klik</a>"; }?>
<?php
mysql_free_result($sesi_member);

mysql_free_result($chat);

mysql_free_result($ikut_me);
?>
